﻿using System;

namespace Quail.DbLogger.Task
{
    public class FinishTestRun : QuailDbLoggerEntry
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FinishTestRun"/> class.
        /// </summary>
        /// <param name="testrunid">The testrunid.</param>
        /// <param name="runstatus">The runstatus.</param>
        /// <param name="finishDate">The time the test run completed</param>
        public FinishTestRun(int testrunid, LogStatus runstatus, DateTime finishDate)
        {
            RunFinishDate = finishDate;
            TestRunId = testrunid;
            RunStatus = runstatus;
        }

        private int TestRunId { get; set; }

        private LogStatus RunStatus { get; set; }

        private DateTime RunFinishDate { get; set; }

        /// <summary>
        /// Finishes the test run
        /// </summary>
        /// <param name="dataContext">the context to use</param>
        public override void Store(QuailServices.QuailDataServiceReference.QuailDataServiceClient dataContext)
        {
            dataContext.FinishTestRun(TestRunId, (int)RunStatus, RunFinishDate);
        }

        /// <summary>
        /// Returns a string representation of the entry for logging purposes
        /// </summary>
        /// <returns>A log string</returns>
        public override string GetLogDetail()
        {
            return string.Format("FinishTestRun({0},{1},{2})", TestRunId, RunStatus, RunFinishDate);
        }
    }
}
